﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Globalization;

namespace AssignmentsManage.Converters
{
    public class CamelCaseToWordsStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            StringBuilder outBuilder = new StringBuilder("");
            if (value != null)
            {
                string startWith = value.ToString();
                for (int i = 0; i < startWith.Length; i++)
                {
                    if (i > 0 && Char.IsUpper(startWith[i]))
                    {
                        outBuilder.Append(" ");
                    }
                    outBuilder.Append(startWith[i]);
                }
            }

            return outBuilder.ToString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException("CamelCaseToWordsStringConverter can only be used for one way conversion.");
        }
    }
}
